﻿@using PayrollExpress.Helpers;
@using PayrollExpress.Models;
@model PayrollListModel

@Html.Partial("_BreadCrumb", Model.BreadCrumb)

@using (Html.BeginForm(BaseHelper.PageAddEditSave.PayrollRefresh.ToString(), Model.ControllerName, FormMethod.Post, new { id = "saveForm" }))
{
    @Html.AntiForgeryToken()

    <fieldset>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-8">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <div class="row">
                                <div class="col-lg-3">
                                    @Html.DropDownListFor(m => m.SelectedWorkLocationID, Model.WorkLocations, new { @class = "form-control input", @onchange = "Refresh()" })
                                    <button id="btnSearch" type="submit" class="hidden" name="command" value="Refresh"></button>
                                </div>
                                <div class="col-lg-9">
                                    @Html.ActionLink(BaseHelper.PageAction.Add.ToString(), BaseHelper.PageAddEditSave.PayrollAddEdit.ToString(), Model.ControllerName, new { workLocationID = Model.SelectedWorkLocationID }, new { @class = "btn btn-primary" })
                                </div>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <table class="table table-striped table-bordered table-hover table-List">
                                <thead class="header">
                                    <tr>
                                        <th>@WorkspaceHelper.ListHeaders.CutOffStartDate.ToDescription()</th>
                                        <th>@WorkspaceHelper.ListHeaders.CutOffEndDate.ToDescription()</th>
                                        <th>@WorkspaceHelper.ListHeaders.ProcessedBy.ToDescription()</th>
                                        <th>@WorkspaceHelper.ListHeaders.DateProcessed.ToDescription()</th>
                                        <th></th>
                                        <th></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @for (var i = 0; i < Model.ListItems.Count(); i++)
                                    {
                                        <tr>
                                            <td>
                                                @Html.HiddenFor(m => Model.ListItems[i].ID)
                                                @Html.ValueFor(m => Model.ListItems[i].CutOffStartDate, "{0:MMMM dd, yyyy}")
                                            </td>
                                            <td>@Html.ValueFor(m => Model.ListItems[i].CutOffEndDate, "{0:MMMM dd, yyyy}")</td>
                                            <td>@Html.DisplayFor(m => Model.ListItems[i].ProcessedBy)</td>
                                            <td>@Html.ValueFor(m => Model.ListItems[i].DateProcessed, "{0:MMMM dd, yyyy}")</td>
                                            <td>
                                                @if (Model.ListItems[i].HasDetails)
                                                { 
                                                    @Html.ActionLink(BaseHelper.Page.PayrollDetails.ToDescription(), BaseHelper.Page.PayrollDetails.ToString(), Model.ControllerName, null, null, null, new { workLocationID = Model.SelectedWorkLocationID, id = Model.ListItems[i].ID }, null)
                                                }
                                                else
                                                {
                                                     @Html.ActionLink(BaseHelper.Page.GeneratePayrollDetails.ToDescription(), BaseHelper.Page.GeneratePayrollDetails.ToString(), Model.ControllerName, null, null, null, new { workLocationID = Model.SelectedWorkLocationID, id = Model.ListItems[i].ID }, new { @class = "btn btn-primary btn-sm" })
                                                }
                                            </td>
                                            <td>@Html.ActionLink(BaseHelper.PageAction.Edit.ToDescription(), BaseHelper.PageAddEditSave.PayrollAddEdit.ToString(), Model.ControllerName, null, null, null, new { workLocationID = Model.SelectedWorkLocationID, id = Model.ListItems[i].ID }, new { @class = "btn btn-primary btn-sm" })</td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </fieldset>
    
    @section Styles {
        @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
    }

    @section Scripts {
        @Scripts.Render("~/plugins/dataTables")

        <script type="text/javascript">

            $(document).ready(function () {
                $('.table-List').dataTable();
            });

            function Refresh() {
                document.getElementById('btnSearch').click();
            }

        </script>
    }
}